﻿using B.S.Business.Domain;
using B.S.Business.ErrorCode;
using B.S.Business.Infacetrue;
using B.S.Business.Read.API.Applications.Dtos;
using B.S.Business.Read.API.Applications.Export;
using MediatR;

namespace B.S.Business.Read.API.Applications.CommandHandler.ExportCommandHandler
{
    /// <summary>
    /// 导出查询
    /// </summary>
    public class SupplierExportQuserCommandHandler : IRequestHandler<SupplierExportQuserCommand, ApiResult<List<SupplierCommodityDto>>>
    {
        private readonly IBaseRepository<SupplierApp> repository;

        public SupplierExportQuserCommandHandler(IBaseRepository<SupplierApp> repository)
        {
            this.repository = repository;
        }
        /// <summary>
        /// 导出供应商查询
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <summary>
        public Task<ApiResult<List<SupplierCommodityDto>>> Handle(SupplierExportQuserCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<SupplierCommodityDto>> result = new ApiResult<List<SupplierCommodityDto>>();

            var list = from a in repository.GetAll()
                       where request.SupplierId.Contains(a.SupplierId)
                       select new SupplierCommodityDto
                       {
                           SupplierId = a.SupplierId,
                           SupplierNumber = a.SupplierNumber,
                           SupplierName = a.SupplierName,
                           OrderAmount = a.OrderAmount,
                           SupplierPhone = a.SupplierPhone,
                           ChuanZhen = a.ChuanZhen,
                           Email = a.Email,
                           //SupplierNamer = a.SupplierNamer,
                           //SupplierAdd = a.SupplierAdd,
                           //SupplierTime = a.SupplierTime,
                           IsDeleted =a.IsDeleted,
                       };

            result.Code = ApiCode.查询成功;
            result.Msg = ApiCode.查询成功.ToString();
            result.Data = list.ToList();

            return Task.FromResult(result);
        }
    }
}
